import os
import json
import time

def save_checkpoint(position, doc1_path, doc2_path):
    """保存检查点位置到文件"""
    checkpoint = {
        "position": position,
        "doc1": doc1_path,
        "doc2": doc2_path,
        "timestamp": time.time()
    }
    with open("checkpoint.json", "w", encoding="utf-8") as f:
        json.dump(checkpoint, f)

def load_checkpoint():
    """从文件加载检查点"""
    if os.path.exists("checkpoint.json"):
        try:
            with open("checkpoint.json", "r", encoding="utf-8") as f:
                return json.load(f)
        except:
            pass
    return None

def remove_checkpoint():
    """删除检查点文件"""
    if os.path.exists("checkpoint.json"):
        os.remove("checkpoint.json")